<template>
    <div>
        <h1>当前求和为:{{ sum }}</h1>
        <h3>当前求和为:{{ bigSum }}</h3>
        <h3>学校{{school}}，性别：{{sex}}，年龄：{{age}}</h3>
        <!--让其收集到的数据全是number类型的 number修饰符-->
        <select v-model.number="n">
            <!--让所有的value全部绑定为数字-->
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
        </select>
        <button @click="increment">+</button>
        <button @click="decrement">-</button>
        <button @click="incrementOdd">当前求和为奇数再加</button>
        <button @click="incrementWait">等一等再加</button>
    </div>
</template>

<script>
    import {mapState,mapGetters} from 'vuex';
export default { 
    name: "Count",
    data() {
        return {
            n:1
        }
    },
    computed: {
        // 累死的写法
        // sum(){
        //     return this.$store.state.sum
        // }
        // 聪明的写法，对象形式
        // ...mapState({sum:'sum',school:"school",age:"age",sex:'sex'})
        // 聪明的写法，数组写法
        ...mapState(['sum','sex','school','age']),
        //mapGetters也和mapState一样
        // ...mapGetters({bigSum:"bigSum"})
        ...mapGetters(['bigSum'])
    },
    methods: {
        decrement() {
            this.$store.commit("JIAN",this.n);
        },
        increment() {
            this.$store.commit("JIA",this.n);
        },


        incrementOdd() {
            this.$store.dispatch("incrementIfOdd",this.n);
        },
        incrementWait() {
            this.$store.dispatch("incrementWait",this.n);
        },
    },
};
</script>

<style>
</style>